package diona.comet

import diona.model.{User, GoogleAuth}
import net.liftweb.http.{CometActor, CometListener}
import diona.auth.{GoogleAuthorization, GoogleOperations}
import net.liftweb.common.Logger

/**
 * User: anton
 * Date: 23.04.11 17:41
 */
class GoogleContentManager extends CometActor with CometListener with Logger
{
  def render =
  {
    info("Google authorization render called")
    val currentToken: Option[GoogleAuth] = GoogleAuth.byUser(User.currentUser.get)
    currentToken match {
      case None => <div class="lift:embed?what=/templates-hidden/googleAuthRequest"/>
      case Some(token) => <div class="lift:embed?what=/templates-hidden/googleContent"/>
    }
  }

  protected def registerWith = GoogleOperations

  override def lowPriority =
  {
    case msg: GoogleAuthorization if msg.user.id.get == User.currentUser.get.id.get => {
      info("Google authorization received")
      reRender(false)
    }
  }
}